using System;
using System.Collections.Generic;
using System.IO;

namespace LibraryImport
{
    public static partial class Artists
    {
        /// <summary>
        /// Search for all files in current folders and checks if the folder is a file
        /// </summary>
        /// <param name="FolderNames">Folder names</param>
        /// <returns>Returns a string colllection of filenames</returns>
        private static String[] GetFileNames(List<String> FolderNames)
        {
            List<String> FileNames = new List<string>();
                       
            for (int i = 0; i < FolderNames.Count; i++)
            {
                try
                {
                    GetID3ArtistTag(FolderNames[i]);
                    FileNames.Add(FolderNames[i]);
                }
                catch (UnauthorizedAccessException)
                {
                    try
                    {
                        FileNames.AddRange(Directory.GetFiles(FolderNames[i], "*.mp3", SearchOption.AllDirectories));
                    }
                    catch (UnauthorizedAccessException)
                    {
                        try
                        {
                            FileNames.AddRange(Directory.GetFiles(FolderNames[i], "*.mp3", SearchOption.TopDirectoryOnly));
                            FolderNames.AddRange(Directory.GetDirectories(FolderNames[i]));
                        }
                        catch (Exception){}
                    }
                    catch (Exception){}
                }
                catch (Exception){}

                Frontend.ProgressPercentage = 100 * i / FolderNames.Count;
            }

            return FileNames.ToArray();
        }
    }
}
